### Makefile --- 
## Time-stamp: <2009-02-20 16:50:17 root>
## Author: root@localhost.localdomain
## Version: $Id: Makefile,v 0.0 2008/10/03 14:59:35 root Exp $
## Keywords: 
## X-URL: 

.SUFFIXES:
.SUFFIXES: .cc .hh .d .o
.PHONY: clean all

LIBS=-L/usr/lib/mysql -lmysqlclient_r -lmysqlpp -lpthread -lgsoap++ -llog4cxx -lrt
# INCS=-I/usr/local/mysql/include/mysql -I/usr/local/include
INCS=-I/usr/local/include -I/usr/include/mysql

CC=gcc -g
CXX=g++ -g
# CFLAGS=-O -Wall -DUNIX -DDEBUG -DTRACE_FILE='"./trace"' -D__PATH__='"$(PWD)/"'

EDF=

### GSoap Related
INCGSOAP=-I/usr/local/share/gsoap/import
GPATH=soap
GWSDL=$(GPATH)/EsmsService_act.wsdl
GESMSH=$(GPATH)/Esms.h
GSOAPC=$(GPATH)/soapC.cpp
GSOAPCOBJ=$(GPATH)/soapC.o
GSOAPPROXYC=$(GPATH)/soapEsmsServiceSoapProxy.cpp
GSOAPPROXYCOBJ=$(GPATH)/soapEsmsServiceSoapProxy.o

GOBJ=$(GPATH)/wrapesms.o
GSOURCE=$(GPATH)/wrapesms.cc

TARGET=fhomed
# SOURCES=alarm.cc db.cc dispatch.cc heart.cc inifile.cc mutex.cc proto.cc server.cc thread.cc main.cc
OBJECTS=alarm.o db.o dispatch.o heart.o inifile.o log.o mutex.o proto.o server.o thread.o main.o excep.o func.o ctrl.o signal.o

all: $(TARGET)
	@sh prepare.sh
# 	@cp bakehome.sh /usr/local/bin/
	@perl genheader.pl
	@echo "Compile finnished!"

install: $(TARGET)
	@cp $(TARGET) /usr/local/bin/
	@echo "copy target file into /usr/local/bin/"


$(GESMSH):$(GWSDL)
	wsdl2h -o $@ $<

$(GSOAPC) $(GSOAPPROXYC): $(GESMSH)
	soapcpp2 -t -i -C $< $(INCGSOAP)

$(GSOAPCOBJ): $(GSOAPC)
	$(CXX) -DWITH_COOKIES -c $< -o $@

$(GSOAPPROXYCOBJ): $(GSOAPPROXYC)
	$(CXX) -DWITH_COOKIES -c $< -o $@

$(GOBJ): $(GSOURCE)
	$(CXX) -c $< -o $@


# fhomed: common.hh $(OBJS)
# 	$(CXX) -o $@ $(OBJS) $(INCS) $(LIBS)

$(OBJECTS): %.o: %.cc %.hh common.hh
	$(CXX) -c $< -o $@ $(CFLAGS) $(INCS)

OBJALL=$(OBJECTS) $(GOBJ) $(GSOAPCOBJ) $(GSOAPPROXYCOBJ)
$(TARGET): $(OBJALL)
	$(CXX) -Wall $(OBJALL) -o $(TARGET) $(INCS) $(LIBS)

# $(filter %.o,$(OBJECTS)): %.d: %.cc
# 	@set -e; rm -f $@;\
# 	$(CXX) -MM $(CFLAGS) $< > $@.$$$$;\
# 	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@;\
# 	rm -f $@.$$$$

# 	echo "	$(CXX) -c $<" >> $@.$$$$;

# -include $(OBJECTS:.o=.d)

# .c:
# 	$(CXX) -o $@ $< $(CFLAGS) $(INCS) $(LIBS)

%.o: %.cc %.hh common.hh
	$(CXX) -o $@ -c $< $(CFLAGS) $(INCS)

clean:
	-rm $(OBJECTS) $(GOBJ) $(GSOAPCOBJ) $(GSOAPPROXYCOBJ) $(TARGET) *.d

### Makefile ends here
